package com.crawler.comm

import com.typesafe.config.Config

/**
  * Created by tongtao.zhu on 2016/12/16.
  */
object CrawlerConfig {
  val filePersist = "crawler.persist"
  val fileJar = "crawler.jar"
  val phantomjsPath = "crawler.phantomjs-binary-path"
  val maxFileSize = "crawler.max-file-size"
  val sendMaxSize = "crawler.send-max-size"
  val expiredTime = "crawler.expired-time"
  val proxyFile = "crawler.proxy-file"
  val chromeDriver = "crawler.chrome-driver"
  val retryCount = "crawler.retry-count"
  val proxyHelperDir = "crawler.proxy-helper-dir"
  val proxyExtensionDir = "crawler.proxy-extension-dir"
}

class CrawlerConfig(val config: Config) {
  val filePersist: String = getString(CrawlerConfig.filePersist)
  val fileJar: String = getString(CrawlerConfig.fileJar)
  val phantomjsPath = getString(CrawlerConfig.phantomjsPath)
  val maxFileSize = getLong(CrawlerConfig.maxFileSize)
  val sendMaxSize = getLong(CrawlerConfig.sendMaxSize)
  val expiredTime = getLong(CrawlerConfig.expiredTime)
  val proxyFile = getString(CrawlerConfig.proxyFile)
  val chromeDriver = getString(CrawlerConfig.chromeDriver)
  val retryCount = getInt(CrawlerConfig.retryCount)
  val proxyHelperDir = getString(CrawlerConfig.proxyHelperDir)
  val proxyExtensionDir = getString(CrawlerConfig.proxyExtensionDir)

  def getString(key: String): String = {
    config.getString(key)
  }

  def getLong(key: String): Long = {
    config.getLong(key)
  }

  def getInt(key: String): Integer = {
    config.getInt(key)
  }
}
